<?php  

/**
 * Helper for displaying menu, uses recursion for drawing html lists
 * It's usfeull for static web pages, where all requests are handled by index/index 
 *
 * @since 2011-07-23
 * @author Jakub Kułak <jakub.kulak@gmail.com>
 */
class Zend_View_Helper_DrawNavigation extends Zend_View_Helper_Abstract 
{ 
    public function drawNavigation($navigation, $parent = null, $level = null, $class = null) {
        if (null === $level) $level = 0;
        $this->_draw($navigation, $parent, $level, $class);
    }

    private function _draw($navigation, $parent, $level, $class = null)
    {
        $level++;

        echo sizeof($navigation)?'<ul class="' . (isset($parent)?($parent->getRoute() . ' '):'') . 'level' . $level . (isset($class)?(' ' . $class):'') . '">':'';
        foreach ($navigation as $page) {
            if ($page->getRoute() == Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName()) {
                echo '<li class="active level' . $level . '">' . $this->view->translate($page->getLabel());
            } else {
                echo '<li class="level' . $level . '"><a class="menuitem" href="' . $page->getHref() . '">' . $this->view->translate($page->getLabel()) . '</a>';
            }

            $subpages = $page->getPages();
            if (sizeof($subpages)) {
                $this->_draw($subpages, $page, $level);
            }

            echo '</li>';
        }
        echo sizeof($navigation)?'</ul>':'';
    }
}